<template>
	<view class="container">
		<view v-if="workerData.length > 0">
			<block v-for="(item,index) in workerData" :key="index">
				<view class="user-item white-bg z-b-r u-margin-bottom-20 u-padding-20 z-font-lg u-flex">
					<view class="u-flex-1">
						<view class="">
							<text>姓名：</text>
							<text>{{ item.name }}({{ item.sex }})</text>
						</view>
						<view class="">
							<text>联系电话：</text>
							<text>{{item.phone}}</text>
						</view>
						<view class="">
							<text>家庭住址：</text>
							<text>{{item.address}} {{ item.detailAddre }}</text>
						</view>
					</view>
					<view>
						<u-button :disabled="isRelieve" type="warning" @click="relieveBindWorkerHandle(item.wkID,index)" size="mini">解除绑定</u-button>
					</view>
				</view>
			</block>
		</view>
		<view v-else class="">
			<empty-data tipText="您还没有员工"></empty-data>
		</view>
		
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	import {mapState} from "vuex";
	export default {
		data() {
			return {
				workerData:[],
				workers:[],
				isRelieve:false
			}
		},
		computed:{
			...mapState({
				token:"token",
				wkID:"wkID",
				userID:"userID",
				pm_company:"pm_company"
			})
		},
		onLoad() {
			this.getWKdatas()
		},
		methods: {
			//解除绑定
			async relieveBindWorkerHandle(wkID,index){
				let {token,userID} = this;
				this.$loading("正在解绑")
				this.isRelieve = true;
				let res = await this.$network({
					api:"main",
					data:{
						action:"user/relieveBindWorker",
						data:{
							userID,
							token,
							wkID
						}
					}
				})
				
				uni.hideLoading();
				this.isRelieve = false;
				if(res.status === 0){
					this.$refs.uToast.show({
						title: '成功解绑',
						type: 'success'
					})
					this.workerData.splice(index,1);
				} else {
					this.$refs.uToast.show({
						title: '稍后重试',
						type: 'warning'
					})
				}
			},
			async getWKdatas(){
				//获取绑定的员工
				let {token,pm_company} = this;
				this.$loading("正在加载")
				let res = await this.$network({
					api:"main",
					data:{
						action:"user/getUserDataByPmCompany",
						data:{
							pm_company,
							token
						}
					}
				})

				uni.hideLoading();
				if(res.status === 0){
					this.workerData = res.data;
				} else {
					this.$refs.uToast.show({
						title: '没有数据',
						type: 'warning'
					})
				}
			}
		}
	}
</script>

<style>

</style>
